﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyTiemVang.DAO
{    
    class QuiDinhDAO
    {
        public static void ChangePolicy(QUIDINH qd, string tenQd )
        {
            QUANLYTIEMVANGEntities db = new QUANLYTIEMVANGEntities();
            var query = (from d in db.QUIDINHs
                        where d.TenQuyDinh.Equals(tenQd)
                        select d).ToList();
            if (query.Count > 0)
            {
                query.First().GiaTri = qd.GiaTri;
                db.SaveChanges();
            }
        }

        public static QUIDINH GetTimeToLock()
        {
            QUANLYTIEMVANGEntities db = new QUANLYTIEMVANGEntities();
            var query = from d in db.QUIDINHs
                        where string.Equals(d.TenQuyDinh, "ThoiGianKhoa")
                        select d;
            if (query.Count() > 0)
                return query.First();
            return null;
        }

        public static QUIDINH GetMaxDebt()
        {
            QUANLYTIEMVANGEntities db = new QUANLYTIEMVANGEntities();
            var query = from d in db.QUIDINHs
                        where string.Equals(d.TenQuyDinh, "NoToiDa")
                        select d;
            if (query.Count() > 0)
                return query.First();
            return null;
        }

        public static QUIDINH GetMaxTimePay()
        {
            QUANLYTIEMVANGEntities db = new QUANLYTIEMVANGEntities();
            var query = from d in db.QUIDINHs
                        where string.Equals(d.TenQuyDinh, "ThoiGianTraChamToiDa")
                        select d;
            if (query.Count() > 0)
                return query.First();
            return null;
        }
    }
}
